package com.qms.tubu.tools;

import android.content.Context;
import android.content.SharedPreferences;

import com.qms.tubu.bean.AccountBean;

/**
 * Created by Mad on 2015/7/22.
 */
public class SPHelper {
    public final static String SP_CONFIG="config";
    public final static String SP_ACCOUNT="account";
    public final static String LOGIN_TYPE_NORMAL="normal";
    public final static void saveAccount(Context context,AccountBean account) {
        SharedPreferences.Editor editor=context.getSharedPreferences(SP_ACCOUNT,Context.MODE_PRIVATE).edit();
        editor.putString("id",account.getId());
        editor.putString("birthday",account.getBirthday());
        editor.putInt("sex", account.getSex());
        editor.putString("phone", account.getPhone());
        editor.putString("nickname", account.getNickname());
        editor.putString("headimgurl", account.getHeadimgurl());
        editor.putString("city", account.getCity());
        editor.putString("province", account.getProvince());
        editor.putString("token", account.getToken());
        editor.putString("login_type",account.getLoginType());
        editor.putString("signature",account.getSignature());
        editor.commit();
    }
    public final static AccountBean getAccount(Context context)
    {
        SharedPreferences preferences=context.getSharedPreferences(SP_ACCOUNT,Context.MODE_PRIVATE);
        String loginType=preferences.getString("login_type",null);
        if(loginType==null)
            return null;
        AccountBean account=new AccountBean();
        account.setLoginType(loginType);
        account.setBirthday(preferences.getString("birthday","1990-01-01"));
        account.setId(preferences.getString("id","0"));
        account.setSex(preferences.getInt("sex",1));
        account.setPhone(preferences.getString("phone",""));
        account.setNickname(preferences.getString("nickname",""));
        account.setHeadimgurl(preferences.getString("headimgurl",""));
        account.setCity(preferences.getString("city",""));
        account.setProvince(preferences.getString("province",""));
        account.setToken(preferences.getString("token",""));
        account.setSignature(preferences.getString("signature",""));
        return  account;
    }
}
